﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PostSharp.Laos;
using System.Diagnostics;

namespace NSsh.Common.Aspects
{
    [Serializable]
    [Trace(null, AttributeExclude = true)]
    public sealed class TraceAttribute : OnMethodBoundaryAspect
    {
        private readonly string _category;

        public TraceAttribute(string category)
        {
            this._category = category;
        }

        public string Category { get { return _category; } }

        [DebuggerStepThrough]
        public override void OnEntry(MethodExecutionEventArgs eventArgs)
        {
            Trace.WriteLine(
                string.Format("Entering {0}.{1}.",
                               eventArgs.Method.DeclaringType.Name,
                               eventArgs.Method.Name),
                this._category);
        }

        [DebuggerStepThrough]
        public override void OnExit(MethodExecutionEventArgs eventArgs)
        {
            Trace.WriteLine(
                string.Format("Leaving {0}.{1}.",
                               eventArgs.Method.DeclaringType.Name,
                               eventArgs.Method.Name),
                this._category);
        }
    }
}
